#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string s1,s2;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='#'&&!s1.empty()) s1.pop_back();
            if(s[i]!='#') s1.push_back(s[i]);
        }
        for(int i=0;i<t.size();i++)
        {
            if(t[i]=='#'&&!s2.empty()) s2.pop_back();
            if(t[i]!='#') s2.push_back(t[i]);
        }
        return s1==s2;
    }
};
int main()
{
    string s1="y#fo##f";
    string s2="y#f#o##f";
    Solution so;
    so.backspaceCompare(s1,s2);
    return 0;
}